﻿<cfcomponent 
			displayname="exitinterview" 
			hint="Functions for exit interview are here" 
			output="false"
>

	<cffunction 
				name="submitexitinterviewform"
				output="false"
				returnformat="plain" 
				returntype="String"
	>
	<cfargument 
			name="processkey"
	>
	
			<cfset resultObj = EntityLoad("ginexitinterviewform", {employeenumber="#trim(form.employeenumber)#"}) >
			<cfif isdefined("resultObj") >
				<cfif ArrayLen(resultObj) GT 0 >
				<cfreturn  
						"recordalreadyexist"
			    >
				</cfif>
			<cfelse>
				
			</cfif>
			
		    <cfset processkey = processkey>

			<cfset controlnumber = trim(form.controlnumber) />
			<cfset company = trim(form.company) />
			<cfset dateofaccomplishment = trim(form.dateofaccomplishment) />
			<cfset nameofemployee = trim(form.nameofemployee) />
			<cfset employeenumber = trim(form.employeenumber) />
			<cfset immediatesuperior = trim(form.immediatesuperior) />
			<cfset department = trim(form.department) />
			<cfset age = trim(form.age) />
			<cfset currentposition = trim(form.currentposition) />
			<cfset positionuponhire = trim(form.positionuponhire) />
			<cfset datehired = trim(form.datehired) />
			<cfset effectdateresign = trim(form.effectdateresign) />
			<cfset lengthofservice = trim(form.lengthofservice) />
			
			<cfif isdefined('form.localopportunity1')>
				<cfset localopportunity1 = trim(form.localopportunity1) />
			<cfelse>
				<cfset localopportunity1 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity2')>
				<cfset localopportunity2 = trim(form.localopportunity2) />
			<cfelse>
				<cfset localopportunity2 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity3')>
				<cfset localopportunity3 = trim(form.localopportunity3) />
			<cfelse>
				<cfset localopportunity3 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity4')>
				<cfset localopportunity4 = trim(form.localopportunity4) />
			<cfelse>
				<cfset localopportunity4 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity5')>
				<cfset localopportunity5 = trim(form.localopportunity5) />
			<cfelse>
				<cfset localopportunity5 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity6')>
				<cfset localopportunity6 = trim(form.localopportunity6) />
			<cfelse>
				<cfset localopportunity6 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity7')>
				<cfset localopportunity7 = trim(form.localopportunity7) />
			<cfelse>
				<cfset localopportunity7 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity8')>
				<cfset localopportunity8 = trim(form.localopportunity8) />
			<cfelse>
				<cfset localopportunity8 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity9')>
				<cfset localopportunity9 = trim(form.localopportunity9) />
			<cfelse>
				<cfset localopportunity9 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity10')>
				<cfset localopportunity10 = trim(form.localopportunity10) />
			<cfelse>
				<cfset localopportunity10 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity11')>
				<cfset localopportunity11 = trim(form.localopportunity11) />
			<cfelse>
				<cfset localopportunity11 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity12')>
				<cfset localopportunity12 = trim(form.localopportunity12) />
			<cfelse>
				<cfset localopportunity12 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity13')>
				<cfset localopportunity13 = trim(form.localopportunity13) />
			<cfelse>
				<cfset localopportunity13 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity14')>
				<cfset localopportunity14 = trim(form.localopportunity14) />
			<cfelse>
				<cfset localopportunity14 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity15')>
				<cfset localopportunity15 = trim(form.localopportunity15) />
			<cfelse>
				<cfset localopportunity15 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity16')>
				<cfset localopportunity16 = trim(form.localopportunity16) />
			<cfelse>
				<cfset localopportunity16 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity17')>
				<cfset localopportunity17 = trim(form.localopportunity17) />
			<cfelse>
				<cfset localopportunity17 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity18')>
				<cfset localopportunity18 = trim(form.localopportunity18) />
			<cfelse>
				<cfset localopportunity18 = '' />	
			</cfif>
			<cfif isdefined('form.localopportunity19')>
				<cfset localopportunity19 = trim(form.localopportunity19) />
			<cfelse>
				<cfset localopportunity19 = '' />	
			</cfif>
			
			<cfset industrynxtemp = trim(form.industrynxtemp) />
			<cfset companynxtemp = trim(form.companynxtemp) />
			<cfset expectedtomeet = trim(form.expectedtomeet) />
			<cfset expectmeetremarks = trim(form.expectmeetremarks) />
			<cfset changesaffected = trim(form.changesaffected) />
			<cfset changesremarks = trim(form.changesremarks) />
			<cfset developfull = trim(form.developfull) />
			<cfset developfullremarks = trim(form.developfullremarks) />
			<cfset answerproblems = trim(form.answerproblems) />
			<cfset problemsremarks = trim(form.problemsremarks) />
			<cfset improvements = trim(form.improvements) />
			<cfset improvementsremarks = trim(form.improvementsremarks) />
			<cfset factorsfacilitated = trim(form.factorsfacilitated) />
			<cfset factorshindered = trim(form.factorshindered) />
			<cfset comppolicies = trim(form.comppolicies) />
			<cfset comppolicyremarks = trim(form.comppolicyremarks) />
			<cfset compreputation = trim(form.compreputation) />
			<cfset compreputationremarks = trim(form.compreputationremarks) />
			<cfset seniorlead = trim(form.seniorlead) />
			<cfset seniorleadremarks = trim(form.seniorleadremarks) />
			<cfset superiorimmed = trim(form.superiorimmed) />
			<cfset superiorimmedremarks = trim(form.superiorimmedremarks) />
			<cfset coworkers = trim(form.coworkers) />
			<cfset coworkersremarks = trim(form.coworkersremarks) />
			<cfset customers = trim(form.customers) />
			<cfset customersremarks = trim(form.customersremarks) />
			<cfset salary = trim(form.salary) />
			<cfset salaryremarks = trim(form.salaryremarks) />
			<cfset benefits = trim(form.benefits) />
			<cfset benefitsremarks = trim(form.benefitsremarks) />
			<cfset perfmgnt = trim(form.perfmgnt) />
			<cfset perfmgntremarks = trim(form.perfmgntremarks) />
			<cfset recognition = trim(form.recognition) />
			<cfset recognitionremarks = trim(form.recognitionremarks) />
			<cfset workk = trim(form.work) />
			<cfset workremarks = trim(form.workremarks) />
			<cfset resourcespeople = trim(form.resourcespeople) />
			<cfset resourcespeopleremarks = trim(form.resourcespeopleremarks) />
			<cfset empcommu = trim(form.empcommu) />
			<cfset empcommuremarks = trim(form.empcommuremarks) />
			<cfset workprocess = trim(form.workprocess) />
			<cfset workprocessremarks = trim(form.workprocessremarks) />
			<cfset careeropp = trim(form.careeropp) />
			<cfset careeroppremarks = trim(form.careeroppremarks) />
			<cfset traindevopp = trim(form.traindevopp) />
			<cfset traindevoppremarks = trim(form.traindevoppremarks) />
			<cfset worklifebal = trim(form.worklifebal) />
			<cfset worklifebalremarks = trim(form.worklifebalremarks) />
			<cfset workcondition = trim(form.workcondition) />
			<cfset workconditionremarks = trim(form.workconditionremarks) />
			<cfset overallwork = trim(form.overallwork) />
			<cfset overallworkremarks = trim(form.overallworkremarks) />
			<cfset applyfutureyes = trim(form.applyfutureyes) />
			<cfset applyfutureremarks = trim(form.applyfutureremarks) />
			<cfset remarksfinalresignee = trim(form.remarksfinalresignee) />
			<cfset resigneeremarkdate = trim(form.resigneeremarkdate) />
			<cfset rmrksfinterviewer = trim(form.rmrksfinterviewer) />
			<cfset interviewerrmrkdate = trim(form.interviewerrmrkdate) />
			
			<cfset eiObj = EntityNew("ginexitinterviewform") >
			
			<cfset eiObj.setControlnumber(controlnumber) >
			<cfset eiObj.setCompany(company) >
			<cfif len(dateofaccomplishment) GT 5> 
			 <cfset eiObj.setDateofaccomplishment(dateofaccomplishment) >
			</cfif>
			<cfset eiObj.setNameofemployee(nameofemployee) >
			<cfset eiObj.setEmployeenumber(employeenumber) >
			<cfset eiObj.setImmediatesuperior(immediatesuperior) >
			<cfset eiObj.setDepartment(department) >
			<cfset eiObj.setAge(age) >
			<cfset eiObj.setCurrentposition(currentposition) >
			<cfset eiObj.setPositionuponhire(positionuponhire) >
			<cfif len(datehired) GT 5> 
			 <cfset eiObj.setDatehired(datehired) >
			</cfif>
			<!---<cfset eiObj.setDatehired(datehired) >--->
			<cfif len(effectdateresign) GT 5> 
			 <cfset eiObj.setEffectdateresign(effectdateresign) >
			</cfif>
			<!---<cfset eiObj.setEffectdateresign(effectdateresign) >--->
			<cfset eiObj.setLengthofservice(lengthofservice) >
			<cfset eiObj.setLocalopportunity1(localopportunity1) >
			<cfset eiObj.setLocalopportunity2(localopportunity2) >
			<cfset eiObj.setLocalopportunity3(localopportunity3) >
			<cfset eiObj.setLocalopportunity4(localopportunity4) >
			<cfset eiObj.setLocalopportunity5(localopportunity5) >
			<cfset eiObj.setLocalopportunity6(localopportunity6) >
			<cfset eiObj.setLocalopportunity7(localopportunity7) >
			<cfset eiObj.setLocalopportunity8(localopportunity8) >
			<cfset eiObj.setLocalopportunity9(localopportunity9) >
			<cfset eiObj.setLocalopportunity10(localopportunity10) >
			<cfset eiObj.setLocalopportunity11(localopportunity11) >
			<cfset eiObj.setLocalopportunity12(localopportunity12) >
			<cfset eiObj.setLocalopportunity13(localopportunity13) >
			<cfset eiObj.setLocalopportunity14(localopportunity14) >
			<cfset eiObj.setLocalopportunity15(localopportunity15) >
			<cfset eiObj.setLocalopportunity16(localopportunity16) >
			<cfset eiObj.setLocalopportunity17(localopportunity17) >
			<cfset eiObj.setLocalopportunity18(localopportunity18) >
			<cfset eiObj.setLocalopportunity19(localopportunity19) >
			<cfset eiObj.setIndustrynxtemp(industrynxtemp) >
			<cfset eiObj.setCompanynxtemp(companynxtemp) >
			<cfset eiObj.setExpectedtomeet(expectedtomeet) >
			<cfset eiObj.setExpectmeetremarks(expectmeetremarks) >
			<cfset eiObj.setChangesaffected(changesaffected) >
			<cfset eiObj.setChangesremarks(changesremarks) >
			<cfset eiObj.setDevelopfull(developfull) >
			<cfset eiObj.setDevelopfullremarks(developfullremarks) >
			<cfset eiObj.setAnswerproblems(answerproblems) >
			<cfset eiObj.setProblemsremarks(problemsremarks) >
			<cfset eiObj.setImprovements(improvements) >
			<cfset eiObj.setImprovementsremarks(improvementsremarks) >
			<cfset eiObj.setFactorsfacilitated(factorsfacilitated) >
			<cfset eiObj.setFactorshindered(factorshindered) >
			<cfset eiObj.setComppolicies(comppolicies) >
			<cfset eiObj.setComppolicyremarks(comppolicyremarks) >
			<cfset eiObj.setCompreputation(compreputation) >
			<cfset eiObj.setCompreputationremarks(compreputationremarks) >
			<cfset eiObj.setSeniorlead(seniorlead) >
			<cfset eiObj.setSeniorleadremarks(seniorleadremarks) >
			<cfset eiObj.setSuperiorimmed(superiorimmed) >
			<cfset eiObj.setSuperiorimmedremarks(superiorimmedremarks) >
			<cfset eiObj.setCoworkers(coworkers) >
			<cfset eiObj.setCoworkersremarks(coworkersremarks) >
			<cfset eiObj.setCustomers(customers) >
			<cfset eiObj.setCustomersremarks(customersremarks) >
			<cfset eiObj.setSalary(salary) >
			<cfset eiObj.setSalaryremarks(salaryremarks) >
			<cfset eiObj.setBenefits(benefits) >
			<cfset eiObj.setBenefitsremarks(benefitsremarks) >
			<cfset eiObj.setPerfmgnt(perfmgnt) >
			<cfset eiObj.setPerfmgntremarks(perfmgntremarks) >
			<cfset eiObj.setRecognition(recognition) >
			<cfset eiObj.setRecognitionremarks(recognitionremarks) >
			<cfset eiObj.setWorkk(workk) >
			<cfset eiObj.setWorkremarks(workremarks) >
			<cfset eiObj.setResourcespeople(resourcespeople) >
			<cfset eiObj.setResourcespeopleremarks(resourcespeopleremarks) >
			<cfset eiObj.setEmpcommu(empcommu) >
			<cfset eiObj.setEmpcommuremarks(empcommuremarks) >
			<cfset eiObj.setWorkprocess(workprocess) >
			<cfset eiObj.setWorkprocessremarks(workprocessremarks) >
			<cfset eiObj.setCareeropp(careeropp) >
			<cfset eiObj.setCareeroppremarks(careeroppremarks) >
			<cfset eiObj.setTraindevopp(traindevopp) >
			<cfset eiObj.setTraindevoppremarks(traindevoppremarks) >
			<cfset eiObj.setWorklifebal(worklifebal) >
			<cfset eiObj.setWorklifebalremarks(worklifebalremarks) >
			<cfset eiObj.setWorkcondition(workcondition) >
			<cfset eiObj.setWorkconditionremarks(workconditionremarks) >
			<cfset eiObj.setOverallwork(overallwork) >
			<cfset eiObj.setOverallworkremarks(overallworkremarks) >
			<cfset eiObj.setApplyfutureyes(applyfutureyes) >
			<cfset eiObj.setApplyfutureremarks(applyfutureremarks) >
			<cfset eiObj.setRemarksfinalresignee(remarksfinalresignee) >
			<cfif len(resigneeremarkdate) GT 5> 
			 <cfset eiObj.setResigneeremarkdate(resigneeremarkdate) >
			</cfif>
			<!---<cfset eiObj.setResigneeremarkdate(resigneeremarkdate) >--->
			<cfset eiObj.setRmrksfinterviewer(rmrksfinterviewer) >
			<cfif len(interviewerrmrkdate) GT 5> 
			 <cfset eiObj.setInterviewerrmrkdate(interviewerrmrkdate) >
			</cfif> 
			<!---<cfset eiObj.setInterviewerrmrkdate(interviewerrmrkdate) >--->
			
			
			<cfset EntitySave(eiObj) >
			
			<cfreturn  
						controlnumber
			>
	
	</cffunction>
	
	<cffunction 
				name="loadexitinterviewform"
				output="false"
				returnformat="JSON" 
				returntype="String" 
	>
	
	<cfargument 
			name="processkey"
	>
	<cfargument 
			name="employeeaidee"
	>
	<cfargument 
			name="companydsn"
	>
	
	
	
	<cfset processkey = processkey>	 
	<cfset employeeaidee = employeeaidee>  
	<cfset companydsn = companydsn> 

	<cfset this.datasource = companydsn>
	
			
	<cfset eiObj = EntityLoad("cmfpa", {PERSONNELIDNO = #employeeaidee#}, true) >
	
	
	
	<cfif isdefined("eiObj")>
		<cfset eiObjSup = EntityLoad("cmfpa", {PERSONNELIDNO = #eiObj.getSUPERIORCODE()#}, true) >
		<cfif isdefined('eiObjSup')>
			<cfset immedsup = serializejson(eiObjSup.getSALUTATION() & ' ' & eiObjSup.getFIRSTNAME() & ' ' & eiObjSup.getMIDDLENAME() & ' ' & eiObjSup.getLASTNAME()) >
		<cfelse>
			<cfset immedsup = serializejson(eiObj.getSUPERIORCODE()) >
		</cfif>
		
		<cfset eiPersonal = EntityLoad("cin21personalinfo", {PERSONNELIDNO = #eiObj.getSUPERIORCODE()#}, true) >
		<cfif isdefined('eiPersonal')>
			<cfset age = serializejson(eiPersonal.getAGE()) >
		<cfelse>
			<cfset age = 0 >
		</cfif>
		
		<cfset datehired       = eiObj.getDATEHIRED() >
		<cfset datenow         = dateformat(Now(), 'YYYY-MM-DD') >
		<cfset lengthofservice = datediff('m', datehired, datenow ) >
					
					
			<cfset jsonresp = '{
				"success": true,
				"data": {
					"controlnumber": #serializejson(right(createuuid(), 10))#,
					"nameofemployee": #serializejson(eiObj.getSALUTATION() & ' ' & eiObj.getFIRSTNAME() & ' ' & eiObj.getMIDDLENAME() & ' ' & eiObj.getLASTNAME() )#,
					"currentposition": #serializejson(eiObj.getPOSITIONCODE())#,
					"department": #serializejson(eiObj.getDEPARTMENTCODE())#, 
					"immediatesuperior": #immedsup#,
					"age": #age#,
					"datehired": #serializejson(dateformat(datehired, 'YYYY-MM-DD'))#, 
					"lengthofservice": "#lengthofservice# month/s"
					
					}
				}'>
	<cfelse>
		<cfset jsonresp = '{
				"success": true,
				"data": {
					"controlnumber": #serializejson(right(createuuid(), 10))#,
					"nameofemployee": "",
					"currentposition": "",
					"department": "",
					"immediatesuperior": ""
						
					}
				}'>
	</cfif>
			
	<cfreturn
			jsonresp
	>
	
	</cffunction>
	
	
	<cffunction
			name="saveexitmntrdata"
			returnformat="plain" 
			access="remote"
			returntype="string"
    >
    
    <cfargument name="token">
    
    <cfset controlnumber = trim(form.controlnumber) >
	
	
    <cfset eiObj = EntityLoad("ginexitinterviewform", {controlnumber = "#controlnumber#"}, true) >
	<cfset value = trim(form.value)>
	
	<cfset findres = findnocase("date", form.field) >
	<cfif findres GT 0 >
		<cfset value = left(value, 10)>
    </cfif>
	
	<cfset evaluate("eiObj.set#trim(form.field)#(value)") >
	
	<cfset EntitySave(eiObj) >
	
	<cfreturn
			token
	>
	
	</cffunction>
	
	<cffunction name="gridtoexcel"
				returntype="string"
				access="remote"
    >
    
    	<cfargument name = "token">
    
    	<cfquery name="mygriddata"
				 datasource="IBOSE_GLOBAL"
	    >
	    	SELECT * 
			  FROM GINEXITINTERVIEWFORM
		</cfquery>
   
   		<cfspreadsheet  
	    action="write" 
	    filename = "#expandpath('./')#ExitInterviewData.xls"
	    overwrite = "true"				  
	    query = "mygriddata" >
		
		<cfreturn token>
   
    </cffunction>

</cfcomponent>